from django.db import models
from django.contrib.auth.models import User


class SmartLocks(models.Model):
    name = models.CharField(max_length=20, verbose_name='锁名称')

    def __str__(self):
        return self.name



class DefectiveStore(models.Model):
    name = models.CharField(max_length=20, verbose_name='库房名称')

    def __str__(self):
        return self.name


class DefectiveStoreLocks(models.Model):
    smart_locks = models.ForeignKey(SmartLocks, on_delete=models.CASCADE, verbose_name='锁名称')
    defective_store = models.ForeignKey(DefectiveStore, on_delete=models.CASCADE, verbose_name='库房名称')
    quantity = models.IntegerField(verbose_name='数量')

    def __str__(self):
        return self.defective_store.name + ' ' + self.smart_locks.name


class DefectiveStoreOutRecord(models.Model):
    defective_store_locks = models.ForeignKey(DefectiveStoreLocks, on_delete=models.CASCADE, verbose_name='锁名称')
    quantity = models.IntegerField(verbose_name='数量')
    out_time = models.DateTimeField(auto_now_add=True, verbose_name='出库时间')
    operator = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='出库人')

    def __str__(self):
        return self.defective_store_locks.defective_store.name


class DefectiveStoreInRecord(models.Model):
    defective_store_locks = models.ForeignKey(DefectiveStoreLocks, on_delete=models.CASCADE, verbose_name='锁名称')
    quantity = models.IntegerField(verbose_name='数量')
    in_time = models.DateTimeField(auto_now_add=True, verbose_name='入库时间')
    operator = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='入库人')

    def __str__(self):
        return self.defective_store_locks.defective_store.name
